package message

import (
	"gq_volunteer_platform/bean"
	"gq_volunteer_platform/model/activity"
	"gq_volunteer_platform/service/message_queue"

	"github.com/gin-gonic/gin"
)

func Index(c *gin.Context) {

	// var template_id = "ULm-1fgU496yD9my2r-Ip2IQYHurN0asPfrpo1zTAgY"
	// var page = "pages/index/index"

	// var paramData struct {
	// 	Thing1 struct {
	// 		Value string `json:"value"`
	// 	} `json:"thing1"`
	// 	Thing2 struct {
	// 		Value string `json:"value"`
	// 	} `json:"thing2"`
	// 	Time3 struct {
	// 		Value string `json:"value"`
	// 	} `json:"time3"`
	// 	Thing4 struct {
	// 		Value string `json:"value"`
	// 	} `json:"thing4"`
	// }

	// paramData.Thing1.Value = "志愿者推出申请"
	// paramData.Thing2.Value = "里斯"
	// paramData.Time3.Value = "2023-10-01"
	// paramData.Thing4.Value = "志愿者活动"

	var activity_id = 9

	// 根据活动id 查找活动对象
	var act activity.Activity
	if err := bean.MysqlDb.Where("`id`=?", activity_id).First(&act).Error; err != nil {
		bean.Log.Error(err)
		c.String(400, err.Error())
		return
	}

	// 获取用户对象列表
	users, _, err := activity.ActivityFindAdminUser(act)
	if err != nil {
		bean.Log.Error(err)
		return
	}

	for _, item := range users {

		var Openid = item.Openid
		var page = "pages/index/index"
		var applyProject = "万秀区城镇无业纯居民独生子女保健费\n己到账"
		var applyTime = "2020/3/11 10:33"
		var applyTesult = "请注意及时查看"

		if err := message_queue.MessageQueueAddT1(Openid, page, applyProject, applyTime, applyTesult); err != nil {
			// 错误记录
			bean.Log.Error(err)
			// 返回给前端的数据
			c.String(400, err.Error())
			return
		}
	}

	// 返回给前端的数据
	c.String(200, "ok")
}
